<?php

namespace App\Models\Landscaping;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ParkTask extends Model
{
    use SoftDeletes;
    protected $guarded = ['park_task_ids'];

    //查看列表
    public function getList($request)
    {
        $per_page = $request->input('per_page',10);
        return self::orderBy('id','desc')
                ->with(['task_category','site','department','car','employees','files'])
                ->paginate($per_page);
    }

    //任务类型
    public function task_category()
    {
        return $this->belongsTo(\App\Models\Landscaping\TaskCategory::class,'task_category_id','id')->select('id','name');
    }

    //所属站点
    public function site()
    {
    	return $this->belongsTo(\App\Models\OperationManagement\SanitationSite::class,'site_id','id')->select('id','name');
    }

    //查询所属部门
    public function department()
    {
    	return $this->belongsTo(\App\Models\SystemManagement\Department::class,'department_id','id')->select('id','name');
    }

    //查询派遣车辆
    public function car()
    {
    	return $this->belongsTo(\App\Models\CarModels\CarInfo::class,'car_id','id')->select('id','plates_number');
    }

    //查看负责人
    public function employees()
    {
        return $this->belongsTo(\App\Models\SystemManagement\Employee::class,'task_principal_id','id')->select('id','name');
    }

    public function files()
    {
        return $this->hasMany(\App\Models\Landscaping\ParkTaskFile::class,'park_task_id')->with('file');
    }
}
